home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
windc.exe
/
SAMPLE3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-07
|
11KB
|
329 lines
/* sample of POE and help */
#include <stdio.h>
#include <string.h>
#include <bios.h>
#include "wwindefs.h" /* window headers */
#include "wwinstpr.h" /* window structures/prototypes */
void LoadLabels(); /* internal subroutines */
int Process();
void NameHelp(unsigned char helpitem);
void ShiftWindow(struct WWinstruc *winptr, unsigned char scan);
extern WWVIDMEM WWscreenp; /* pointer to screen memory */
extern unsigned int WWScreenLength; /* access to WW defaults */
extern unsigned int WWScreenWidth;
/* define caption window - globally */
struct WWinstruc Caption =
{"Caption",20,3,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
/* define the menu window */
struct WWinstruc Name =
{"Name",4,8,4,63, RED,WHITE,SLN_BDR,WHITE,RED,INV_CSR};
/* define the points of entry for the Name window*/
struct WWinPOE NamePOEs[] ={
{2,10,1,BLACK,NC,'1'}, /* titles */
{2,20,1,BLACK,NC,'1'},
{2,30,1,BLACK,NC,'1'},
{2,40,1,BLACK,NC,'1'},
{2,50,1,BLACK,NC,'1'},
{4,20,20,BLUE,NC,'N'}, /* first name */
{5,20,20,BLUE,NC,'N'}, /* last name */
{7,20,4,BLACK,NC,'M'}, /* OK */
{7,40,8,BLACK,NC,'M'}, /* cancel */
{0,0,0,0,0,0} }; /* dummy */
main()
{
int i, rc;
WWscreenp = WWCOLMEM; /* unecessary - color screen memory is default */
for (i=0;i<27;i++) /* clear screen */
printf(" "
" ");
if ((rc = WWinDef(&Caption)) !=0) /* set up caption screen */
{printf("out of memory"); exit(1);}
WWinLoad(&Caption,1,2,NC,NC,"Press F1 for Help",0);
WWinLoad(&Caption,2,2,NC,NC,"Choose Cancel to exit this program",0);
WWinPut(&Caption);
WWinCurSet(&Caption,1,1); /* set cursor out of the way */
LoadLabels(); /* put the labels in the window */
do
{
rc = Process(); /* process the window */
}
while (rc != 27);
Caption.Cursor = NRM_CSR; /* set cursor back to normal */
WWinCurSet(&Caption,Caption.UseLength,1); /* restore cursor */
}
void LoadLabels()
/* this function loads the window with labels for the POEs.
* Each label is followed by a blank and a 2-digit number which
* is the offset of the beginning of the POE to the beginning of the
* label.
*/
{
unsigned char *LabelPOEs[] =
{ " Mr. [ ] 07", /* POE starts inside the box */
" Mrs. [ ] 08",
" Miss [ ] 08",
" Ms. [ ] 07",
" Dr. [ ] 07",
" First Name : 15",
" Last Name : 15",
" OK 01",
" Cancel 01"};
int i, j, k, rc;
if ((rc = WWinDef(&Name)) !=0)
{printf("out of memory"); exit(1);}
/* load labels for every POE up to the dummy */
for (i=0;(NamePOEs[i].len) != 0;i++)
{
k = strlen(LabelPOEs[i]); /* assigned for easy reading */
j = atoi(LabelPOEs[i]+(k-2)); /* calc offset */
WWinLoad(&Name,NamePOEs[i].row, NamePOEs[i].col-j+1,NC,NC,
LabelPOEs[i],k-3);
}/*for i*/
}
int Process()
/* this function handles the presentation of the POE
* and any verification
*/
{
struct WWinRC retcde;
char titlehold, *Title[5] = {"Mr.","Mrs.","Miss","Ms.","Dr."};
char firstname[21],secondname[21], fullname[50];
int i, activeitem, count, error, done;
done = 0;
activeitem = 1; /* start with first item */
while (!done) /* loop till done != 0 */
{
WWinPut(&Name);
do
{
retcde = WWinDoPOE(&Name,NamePOEs,activeitem);
activeitem = retcde.exval;
if ( (retcde.ascii == 13) /* if ENTER key pressed */
&& (NamePOEs[retcde.exval-1].type != 'M') ) /* but not a menu item */
retcde.ascii = 0; /* ignore it */
if (retcde.scan == 59)
NameHelp(retcde.exval); /* get help */
if ( ((retcde.stat & 0x03) != 00) /* Shift key */
&& (retcde.ascii == 0) ) /* control key */
ShiftWindow(&Name,retcde.scan);
}
while (retcde.ascii == 0); /* require OK or ESC or Cancel */
if ( (retcde.ascii == 27)
|| (retcde.exval == 9) ) /* ESC or Cancel - */
return(27); /* get out */
/* ENTER was pressed - - validate entries */
error = 0; /* start clean */
/* check titles */
count = 0; /* count number chosen */
for (i=0;NamePOEs[i].type == '1';i++)
{
WWinRead(&Name, NamePOEs[i].row, NamePOEs[i].col, &titlehold, 1);
if (titlehold != ' ')
{
strcpy(fullname,"-");
strcat(fullname,Title[i]);
count++;
}
}
if (count != 1) /* if error, load error msg and set error switch */
{
WWinLoad(&Name,8,15,BLUE,NCB,"Choose ONE and only ONE Title ",0);
error = 1;
}
if (!error) /* continue checking only if no errors */
{
/* check names */
/* can't read to a blank becuase names may
contain blanks */
WWinRead(&Name, NamePOEs[5].row, NamePOEs[5].col,
firstname,NamePOEs[5].len);
WWinRead(&Name, NamePOEs[6].row, NamePOEs[6].col,
secondname,NamePOEs[6].len);
/* strip ending blanks */
while (firstname[strlen(firstname)-1] == ' ')
firstname[strlen(firstname)-1] = '\0';
while (secondname[strlen(secondname)-1] == ' ')
secondname[strlen(secondname)-1] = '\0';
/* must be some non-blanks in the names */
if ( (firstname[0] == '\0') || (secondname[0] == '\0') )
{
WWinLoad(&Name,8,15,BLUE,NCB,"Names may not be blank ",0);
error = 1;
}
}/* end of name check */
if (!error)
{
WWinLoad(&Name,8,15,Name.BackAttr,NC,
" ",0);
/* construct full name and put on caption screen */
strcat(fullname," ");
strcat(fullname,firstname);
strcat(fullname," ");
strcat(fullname,secondname);
strcat(fullname,"-");
WWinLoad(&Caption,3,3,NC,NC,
" ",0); /* clear previous */
WWinLoad(&Caption,3,3,NC,NC,fullname,0);
WWinPut(&Caption);
done = 1;
}
}/* while not done */
}/* end Process */
void NameHelp(unsigned char helpitem)
/* this function sets up the help windows (first time through),
* asks you to chhose between general and specific help, and
* (if specific help requested) provides specific help for the active
* POE.
*/
{
/* define the help windows */
static struct WWinstruc Help[3] = {
{"ChooseHelp",8,2,11,20, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
{"GenHelp",6,15,10,40, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
{"DetailHelp",6,10,10,50, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR} };
int i, rc, activeitem;
unsigned int keyin, statin; /* test input key */
char scan; /* input key scan code */
struct WWinRC retcde; /* return code strucuture for DoPOE */
static char setup_switch = 0;
if (!setup_switch)
{
for (i=0;i<3;i++)
if ((rc = WWinDef(&Help[i])) !=0) /* set up help screens */
{printf("out of memory"); exit(1);}
/* load choosehelp window */
WWinLoad(&Help[0],1,2,NC,NC,"General Help",0);
WWinLoad(&Help[0],2,2,NC,NC,"Detail Help",0);
/* load genhelp window */
WWinLoad(&Help[1],1,2,NC,NC," Enter data and choose OK. ",0);
WWinLoad(&Help[1],3,2,NC,NC,"Try the arrow keys, tab, or shift-tab",0);
WWinLoad(&Help[1],4,2,NC,NC,"Try the backspace, delete, and insert",0);
WWinLoad(&Help[1],5,2,NC,NC,"Try choosing two titles",0);
WWinLoad(&Help[1],6,2,NC,NC,"Try leaving first or last name blank",0);
WWinLoad(&Help[1],8,2,NC,NC,"Use shift-arrow keys to move windows",0);
WWinLoad(&Help[1],10,2,NC,NC,"Press ESC to leave help",0);
/* load some of detail w